var json ={
    a:1,
    b:2,
    c:{},
    d:[],
    e:{a:{},b:1},
    f:" ",
    g:[{a:{},b:1,c:[]}],
    h:[1,""],
    i:null

}
deleteEmptyProperty(json)
console.log(json)
//网上找的方法做了一些修改
function deleteEmptyProperty(object){
    for (var i in object) {
      var value = object[i];
      if (typeof value === 'object') {
        if (Array.isArray(value)) {
          if (value.length == 0) {
            delete object[i];
            continue;
          }
        }
        deleteEmptyProperty(value);
        if (isEmpty(value)) {
          delete object[i];
        }
      } else {
        if (value === null || value === undefined || (typeof value ==='string' && value.replace(/\s+/g, '') === '')) {
          if(Array.isArray(object)) {
            object.splice(i, 1);
          }else delete object[i]
        } else {
        }
      }
    }
  }
  function isEmpty(object) {
    for (var name in object) {
      return false;
    }
    return true;
  }
 